#include <bits/stdc++.h>
#define re register
#define ll long long

using namespace std;

const int N = 4010;
const int mod = 999999999;
int n,q;
int arr[N][N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

struct{
    #define lowbit(x) ((x) & -(x))

    ll tr[N];

    inline void modify(int x,int k){
        for (re int i = x;i <= n;i += lowbit(i)) tr[i] += k;
    }

    inline ll query(int x){
        ll sum = 0;
        for (re int i = x;i;i -= lowbit(i)) sum += tr[i];
        return sum;
    }
    inline ll query(int l,int r){ return query(r) - query(l - 1); }

    #undef lowbit
}T[N];

int main(){
    freopen("fire.in","r",stdin);
    freopen("fire.out","w",stdout);
    n = read(),q = read();
    while (q--){
        int op = read();
        if (op == 1){
            int typ = read(),x = read(),o = read(),k = read();
            if (!typ){
                for (re int i = 1;i <= n;i++){
                    int val = arr[x][i];
                    if (o == 1) val &= k;
                    else if (o == 2) val |= k;
                    else if (o == 3) val ^= k;
                    else (val += k) %= mod;
                    T[x].modify(i,val - arr[x][i]);
                    arr[x][i] = val;
                }
            }
            else{
                for (re int i = 1;i <= n;i++){
                    int val = arr[i][x];
                    if (o == 1) val &= k;
                    else if (o == 2) val |= k;
                    else if (o == 3) val ^= k;
                    else (val += k) %= mod;
                    T[i].modify(x,val - arr[i][x]);
                    arr[i][x] = val;
                }
            }
        }
        else{
            ll sum = 0;
            int x = read(),y = read();
            for (re int i = 1;i <= x;i++) sum += T[i].query(y);
            printf("%lld\n",sum);
        }
    }
    return 0;
}